/* $RCSFile: ADNDynCampaignResponse.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynCampaignResponse.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:32  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Text;
using CrmSdk;

namespace AddonNice.CRMWrapper
{
	public class ADNDynCampaignResponse : ADNDynActivity
	{
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.campaignresponse)
            {}

            public override Type DynType
            { get { return typeof(ADNDynCampaignResponse); } }

            public override string DynTypename
            {   get{ return CrmStr.campaignresponse;}}

            public override DynEntity Build()
            {   return new ADNDynCampaignResponse();}

            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynCampaignResponse(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynCampaignResponse(w,PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynCampaignResponse(w,PrimaryKeyValue);}
        }

        static ADNDynCampaignResponse(){new Ftor();} 

        /// <summary>
		/// Reserved for template methods: do not use directly
		/// </summary>
        public ADNDynCampaignResponse(): base()
		{}

        public ADNDynCampaignResponse(CRMWrapperBase w,string subj)
			: base(w,subj,CrmStr.campaignresponse)
		{}

        public ADNDynCampaignResponse(CRMWrapperBase w,string subj,string desc,DynEntity customer,DynEntity partner)
			: base(w, subj,CrmStr.campaignresponse)
		{
            description =   desc;
            if (customer != null )
                AddCustomer(customer);
            if ( partner!= null )
                AddPartner(partner);
		}

        public ADNDynCampaignResponse(CRMWrapperBase w, Guid CrmId)
			: base(w,CrmStr.campaignresponse, CrmId)
		{}

		public ADNDynCampaignResponse(CRMWrapperBase w, InternalDynamicEntity e)
			: base(w,CrmStr.campaignresponse,e,null,null)
		{}

		public ADNDynCampaignResponse(CRMWrapperBase w, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(w,CrmStr.campaignresponse,e,prop,s)
		{}

        public ADNDynCampaignResponse(ResetWrapperHandler fn,string subj)
			: base(fn,subj,CrmStr.campaignresponse)
		{}

        public ADNDynCampaignResponse(ResetWrapperHandler fn,string subj,string desc,DynEntity customer,DynEntity partner)
			: base(fn, subj,CrmStr.campaignresponse)
		{
            description =   desc;
            if (customer != null )
                AddCustomer(customer);
            if ( partner!= null )
                AddPartner(partner);
		}

        public ADNDynCampaignResponse(ResetWrapperHandler fn, Guid CrmId)
			: base(fn,CrmStr.campaignresponse, CrmId)
		{}

		public ADNDynCampaignResponse(ResetWrapperHandler fn, InternalDynamicEntity e)
			: base(fn,CrmStr.campaignresponse,e,null,null)
		{}

		public ADNDynCampaignResponse(ResetWrapperHandler fn, InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s)
			: base(fn,CrmStr.campaignresponse,e,prop,s)
		{}

        public List<ADNDynActivityParty> PartnersList    =   new List<ADNDynActivityParty>();
        public void AddPartner(DynEntity ent)
        {
            ADNDynActivityParty ap   =   new ADNDynActivityParty(wrapper);
            ap.DefaultPartyName     =   ent.SchemaName;
            ap.partyid              =   ent.PrimaryKeyGuidValue;
            PartnersList.Add(ap);
        }

        [CrmDynAttribute(CrmStr.campaignactivity)]
        public InternalDynamicEntityArray partners 
        {
            get
            {
                return DynamicEntityArrayProperty(CrmStr.partners);
            }
            set
            {
                AddDynamicEntityArrayProperty(CrmStr.partners,value);
            }
        }

        public List<ADNDynActivityParty> CustomerList    =   new List<ADNDynActivityParty>();
        public void AddCustomer(DynEntity ent)
        {
            ADNDynActivityParty ap  =   new ADNDynActivityParty(wrapper);
            ap.DefaultPartyName     =   ent.SchemaName;
            ap.partyid              =   ent.PrimaryKeyGuidValue;
            CustomerList.Add(ap);
        }

        [CrmDynAttribute(CrmStr.campaignresponse)]
        public InternalDynamicEntityArray customer 
        {
            get
            {
                return DynamicEntityArrayProperty(CrmStr.customer);
            }
            set
            {
                AddDynamicEntityArrayProperty(CrmStr.customer,value);
            }
        }
        
        [CrmDynAttribute(CrmStr.campaignresponse)]
        public string companyname
        {
            get
            {
                return StringPropertyValue(CrmStr.companyname);
            }
            set
            {
                AddStringProperty(CrmStr.companyname,value);
            }
        }
 
        [CrmDynAttribute(CrmStr.campaignresponse)]
        public string emailaddress
        {
            get
            {
                return StringPropertyValue(CrmStr.emailaddress);
            }
            set
            {
                AddStringProperty(CrmStr.emailaddress,value);
            }
        }
        [CrmDynAttribute(CrmStr.campaignresponse)]
        public string firstname
		{
			get
			{
				return StringPropertyValue(CrmStr.firstname);
			}
			set
			{
				AddStringProperty(CrmStr.firstname, value);
			}
		}

        [CrmDynAttribute(CrmStr.campaignresponse)]
		public string lastname
		{
			get
			{
				return StringPropertyValue(CrmStr.lastname);
			}
			set
			{
				AddStringProperty(CrmStr.lastname, value);
			}
		}

        [CrmDynAttribute(CrmStr.campaignresponse)]
        public string yomicompanyname
        {
            get
            {
                return StringPropertyValue(CrmStr.yomicompanyname);
            }
            set
            {
                AddStringProperty(CrmStr.yomicompanyname,value);
            }
        }
 
        [CrmDynAttribute(CrmStr.campaignresponse)]
        public string yomifirstname
		{
			get
			{
				return StringPropertyValue(CrmStr.yomifirstname);
			}
			set
			{
				AddStringProperty(CrmStr.yomifirstname, value);
			}
		}

        [CrmDynAttribute(CrmStr.campaignresponse)]
		public string yomilastname
		{
			get
			{
				return StringPropertyValue(CrmStr.yomilastname);
			}
			set
			{
				AddStringProperty(CrmStr.yomilastname, value);
			}
		}

        [CrmDynAttribute(CrmStr.campaignresponse)]
		public string fax
		{
			get
			{
				return StringPropertyValue(CrmStr.fax);
			}
			set
			{
				AddStringProperty(CrmStr.fax,value);
			}
		}

       
        [CrmDynAttribute(CrmStr.campaignresponse)]
		public string telephone
		{
			get
			{
				return StringPropertyValue(CrmStr.telephone);
			}
			set
			{
				AddStringProperty(CrmStr.telephone,value);
			}
		}

        /// <summary>
        /// Owner for this object
        /// </summary>
        [CrmDynAttribute(CrmStr.campaignresponse)]
        public override Guid ownerid
        {
            get
            {
                if ( ContainsKey(CrmStr.ownerid) )
                    return OwnerPropertyValue(CrmStr.ownerid);
                return Guid.Empty;
            }
            set
            {
                AddOwnerProperty(CrmStr.ownerid,CrmStr.systemuser,value);
            }
        }

        /// <summary>
        /// Gets or sets the date on which this campaign response was received.
        /// </summary>
        [CrmDynAttribute(CrmStr.campaignresponse)]
        public string receivedon
        {
            get
            {
                return DateTimePropertyValue(CrmStr.receivedon);
            }
            set
            {
                AddDateTimeProperty(CrmStr.receivedon,value);
            }
        }

        /// <summary>
        /// Gets or sets the typecode of the activity. 
        /// Research
        /// Content Preparation
        /// Target Marketing List Creation
        /// Lead Qualification
        /// Content Distribution
        /// Direct Initial Contact
        /// Direct Follow-Up Contact
        /// Reminder Distribution
        /// </summary>
        [CrmDynAttribute(CrmStr.campaignresponse)]
        public string promotioncodename  
        {
            get
            {
                return StringPropertyValue(CrmStr.promotioncodename);
            }
            set
            {
                AddStringProperty(CrmStr.promotioncodename ,value);
            }
        }
        /// <summary>
        /// Gets or sets the responsecode of the activity. 
        /// 1 Interested
        /// 2 Not Interested
        /// 3 Do Not Send Material
        /// Error
        /// </summary>
        [CrmDynAttribute(CrmStr.campaignresponse)]
        public int responsecode 
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.responsecode);
            }
            set
            {
                AddPicklistProperty(CrmStr.responsecode,value);
            }
        }

        public string responsecodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.responsecode);
            }
        }

	    /// <summary>
	    /// Marketing campaign response channel types.
	    /// </summary>
	    public enum CampaignResponseChannelType : int
	    {
		    Email       =   1,
		    Phone       =   2,
		    Fax         =   3,
		    Letter      =   4,
		    Appointment =   5
	    }

        /// <summary>
        /// Gets or sets the channeltypecode of the activity. 
        /// </summary>
        [CrmDynAttribute(CrmStr.campaignresponse)]
        public int channeltypecode 
        {
            get
            {
                return PicklistPropertyIntValue(CrmStr.channeltypecode );
            }
            set
            {
                AddPicklistProperty(CrmStr.channeltypecode ,value);
            }
        }

        public string channeltypecodeLabel
        {
            get
            {
                return PicklistPropertyLabelValue(CrmStr.channeltypecode );
            }
        }

        protected override Guid internalCreate(bool isAdmin)
        {
            if (CustomerList.Count > 0)
            {
                InternalDynamicEntityArray newArray =   wrapper.Util.MakeDynamicArray(CustomerList);
                AddDynamicEntityArrayProperty(CrmStr.customer, newArray);
            }

            if (PartnersList.Count > 0)
            {
                InternalDynamicEntityArray newArray =   wrapper.Util.MakeDynamicArray(PartnersList);
                AddDynamicEntityArrayProperty(CrmStr.partners, newArray);
            }
            return wrapper.CreateFromDynEntity(this,isAdmin);
        }
    }
}
